using logging;

public interface ISoftWare{
    void run();
}

public interface IHardWare{
    void drive();
    void software_install(ISoftWare software);
    void software_execute();
}

public abstract class HardWare{  // not implement IHardWare
    public SoftWare software{get;set;}

    public abstract void drive();
    public void software_install(SoftWare software){
        this.software = software;
        this.software.env = this;
    }
    public void software_execute(){
        this.software.run();
    }
}

class Windows7: HardWare{
    public override void drive(){
        Log.print("This is a computer, with Windows7 environment.");
    }
}

class Android: HardWare{
    public override void drive(){
        Log.print("This is a cellphone, with Android-8.0 environment.");
    }
}

public abstract class SoftWare: ISoftWare{
    public HardWare env{get;set;}

    protected abstract void function();  // 软件功能代码（我们假设功能代码与环境无关，也就是Java跨平台特性）
    public void run(){  // run() 就是一个 Template Method.
        this.env.drive();  // 软件运行需要载入系统运行时
        this.function();
    }
}

class KOFGame: SoftWare{
    protected override void function(){
        Log.print("King of Fighters: A PLAYSTATION game.");
    }
}

class Demo{
    // 时代在进步，我们有了新的系统
    class FutureOS:HardWare{
        public override void drive(){
            Log.print("A future Operating System, for hardware you never known.");
        }
    }

    // 以及新的软件
    class Chrome: SoftWare{
        protected override void function(){
            Log.print("Chrome: A browser written by google.");
        }
    }

    static void Main(){
        var os = new Windows7();
        os.software_install(new KOFGame());
        os.software_execute();

        os.software_install(new Chrome());  // 安装新软件
        os.software_execute();

        var os2 = new FutureOS();
        os2.software_install(new KOFGame());  // 新系统中复刻经典
        os2.software_execute();
    }
}